#!/usr/bin/python
# -*- coding: UTF-8 -*-

"""
@author: andi
@contact: 643562684@qq.com
@time: 2022/5/28 15:11
"""
import os
import pytest
import subprocess
from datetime import datetime

from common.send_email import SendMail
from common.file_compression import compress
from Conf.setting import REPORT_PATH, BASE_PATH


def runner_pytest():

    pytest.main()
    # 压缩报告文件
    _result = compress(
        dirpath=os.path.join(REPORT_PATH, 'html_report'),
        outFullName=os.path.join(BASE_PATH, 'file', 'result.zip')
    )

    content = f"""
    发送时间: {datetime.now().strftime('%Y-%m-%d')}

    打开方式:  allure open  文件路径

    请确认电脑上已经安装 allure 插件

    如果为下载请参考以下链接进行配置: https://blog.csdn.net/gaomingjian218/article/details/121071149
    """
    subject = "接口测试"

    email = SendMail(content=content, subject=subject)
    email.add_zip(zip_path=_result, zip_name="测试结果")
    email.send_email()

    # allure生成报表，并启动程序
    subprocess.call('allure  generate  -o   OutPuts/html_report  OutPuts/report  --clean', shell=True)
    subprocess.call('allure open -h 192.168.1.141 -p 8880 OutPuts/html_report', shell=True)
